package authorize.controller;

import com.alibaba.fastjson.JSONObject;
import com.bosssoft.trainee.nontax.common.result.Result;
import com.bosssoft.trainee.nontax.entity.dto.TokenResult;
import com.bosssoft.trainee.nontax.entity.dto.UserInfo;
import com.bosssoft.trainee.nontax.entity.vo.RoleVo;
import com.bosssoft.trainee.nontax.entity.vo.UserVo;
import com.bosssoft.trainee.nontax.service.RoleClientService;
import jdk.nashorn.internal.objects.annotations.Constructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Luo Wenlong
 * @date 2022-07-11 21:06
 * @description:
 * @version:
 */
@RestController
public class RoleController {
    @Autowired
    RoleClientService roleClientService;

    @GetMapping("/role/getAll")
    Result<List<RoleVo>> getAllRoles(){
        return roleClientService.getAllRoles();
    }

    @GetMapping("/user/getUserById")
    Result<UserVo> getUserById(@RequestParam("id") Integer id) {
        return roleClientService.getUserById(id);
    }

    @GetMapping("/user/login")
    Result<TokenResult> login(@RequestBody JSONObject jsonObject){
        return roleClientService.login(jsonObject);
    }

    @GetMapping("/user/info")
    Result<UserInfo> getInfo(@RequestParam("token") String token) {
        return roleClientService.getInfo(token);
    }
}
